package com.atguigu.listener;

import jdk.internal.instrumentation.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

//WebListener("关闭servletContext时注销jdbc驱动")
//public class DriverMangerListener implements ServletContextListener {
//    @Override
//    public void contextInitialized (ServletContextEvent sce ){
//    }
//    @Override
//    public void contextDestroyed(ServletContextEvent sce) {
//
//        log.info("[DriverMangerListener]:-------DriverManager deregisterDriver start...");
//        //获取当前以及注册jdbc驱动的枚举（多数据源下依旧可用）
//        Enumeration<Driver> enumeration = DriverManager.getDrivers();
//
//        while (enumeration.hasMoreElements()) {
//            try {
//                //从注册列表移除jdbc驱动
//                DriverManager.deregisterDriver(enumeration.nextElement());
//            } catch (SQLException e) {
//                log.warn("[DriverMangerListener]:-------deregisterDriver error");
//            }
//        }
//        log.info("[DriverMangerListener]:-------DriverManager deregisterDriver end...");
//    }
//}